/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ec.medical.entidades;

import com.ec.medical.interfaces.Imprimible;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "division_geografica")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "DivisionGeografica.findAll", query = "SELECT d FROM DivisionGeografica d"),
    @NamedQuery(name = "DivisionGeografica.findByCodigoDivisionGeografica", query = "SELECT d FROM DivisionGeografica d WHERE d.codigoDivisionGeografica = :codigoDivisionGeografica"),
    @NamedQuery(name = "DivisionGeografica.findByNombre", query = "SELECT d FROM DivisionGeografica d WHERE d.nombre = :nombre"),
    @NamedQuery(name = "DivisionGeografica.findByNivel", query = "SELECT d FROM DivisionGeografica d WHERE d.nivel = :nivel")})
public class DivisionGeografica implements Serializable, Imprimible {

    @Basic(optional = false)
    @NotNull
    @Column(name = "nivel")
    private int nivel;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "codigo_division_geografica")
    private Integer codigoDivisionGeografica;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "nombre")
    private String nombre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "divisionGeografica")
    private List<DireccionCliente> direccionClientes;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "divisionGeograficaPadre")
    private List<DivisionGeografica> divisionGeograficas;
    @JoinColumn(name = "codigo_division_geografica_padre", referencedColumnName = "codigo_division_geografica")
    @ManyToOne
    private DivisionGeografica divisionGeograficaPadre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "divisionGeografica")
    private List<Prestador> prestador;

    public DivisionGeografica() {
    }

    public DivisionGeografica(Integer codigoDivisionGeografica) {
        this.codigoDivisionGeografica = codigoDivisionGeografica;
    }

    public DivisionGeografica(Integer codigoDivisionGeografica, String nombre, Integer nivel) {
        this.codigoDivisionGeografica = codigoDivisionGeografica;
        this.nombre = nombre;
        this.nivel = nivel;
    }

    public Integer getCodigoDivisionGeografica() {
        return codigoDivisionGeografica;
    }

    public void setCodigoDivisionGeografica(Integer codigoDivisionGeografica) {
        this.codigoDivisionGeografica = codigoDivisionGeografica;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    @XmlTransient
    public List<DireccionCliente> getDireccionClientes() {
        return direccionClientes;
    }

    public void setDireccionClientes(List<DireccionCliente> direccionClientes) {
        this.direccionClientes = direccionClientes;
    }

    @XmlTransient
    public List<DivisionGeografica> getDivisionGeograficas() {
        return divisionGeograficas;
    }

    public void setDivisionGeograficas(List<DivisionGeografica> divisionGeograficas) {
        this.divisionGeograficas = divisionGeograficas;
    }

    public DivisionGeografica getDivisionGeograficaPadre() {
        return divisionGeograficaPadre;
    }

    public void setDivisionGeograficaPadre(DivisionGeografica divisionGeograficaPadre) {
        this.divisionGeograficaPadre = divisionGeograficaPadre;
    }

    public List<Prestador> getPrestador() {
        return prestador;
    }

    public void setPrestador(List<Prestador> prestador) {
        this.prestador = prestador;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codigoDivisionGeografica != null ? codigoDivisionGeografica.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DivisionGeografica)) {
            return false;
        }
        DivisionGeografica other = (DivisionGeografica) object;
        if ((this.codigoDivisionGeografica == null && other.codigoDivisionGeografica != null) || (this.codigoDivisionGeografica != null && !this.codigoDivisionGeografica.equals(other.codigoDivisionGeografica))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getNombre();
    }

    @Override
    public String getEtiqueta() {
        return getNombre();
    }

    @Override
    public Object getObjecto() {
        return this;
    }

    public int getNivel() {
        return nivel;
    }

    public void setNivel(int nivel) {
        this.nivel = nivel;
    }
}
